package com.burgeon.backend.config;

import com.burgeon.backend.EnterpriseWeChat.service.EWChatService;
import com.burgeon.backend.SHOPBACKEND.service.AWechatService;
import com.burgeon.backend.SHOPBACKEND.websocket.EWWebSocketServer;
import com.burgeon.backend.SHOPBACKEND.websocket.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.servlet.MultipartConfigElement;
import java.io.File;

/**
 * 配置websocket并开启
 */
@Configuration
public class WebSocketConfig {
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        factory.setMaxFileSize(1024 * 1024 * 100); // 限制上传文件大小
        return factory.createMultipartConfig();
    }

    @Bean
    public ServerEndpointExporter serverEndpointExporter() {
        return new ServerEndpointExporter();
    }

    @Autowired
    private void setWechatService(AWechatService wechatService) {
        WebSocketServer.wechatService = wechatService;
    }
    @Autowired
    private void setEWChatService(EWChatService ewChatService) {
        EWWebSocketServer.ewChatService = ewChatService;
    }
}